package com.titleevaluation.controller;

import com.titleevaluation.entity.AcademicAchievements;
import com.titleevaluation.service.AcademicAchievementsService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/applications/{applicationId}/academic-achievements")
public class AcademicAchievementsController {

    private final AcademicAchievementsService academicAchievementsService;

    public AcademicAchievementsController(AcademicAchievementsService academicAchievementsService) {
        this.academicAchievementsService = academicAchievementsService;
    }

    @PostMapping
    public ResponseEntity<AcademicAchievements> createAcademicAchievements(@PathVariable Long applicationId, @RequestBody AcademicAchievements academicAchievements) {
        AcademicAchievements createdAcademicAchievements = academicAchievementsService.createAcademicAchievements(applicationId, academicAchievements);
        return ResponseEntity.ok(createdAcademicAchievements);
    }

    @GetMapping
    public ResponseEntity<List<AcademicAchievements>> getAcademicAchievementsByApplicationId(@PathVariable Long applicationId) {
        List<AcademicAchievements> academicAchievements = academicAchievementsService.getAcademicAchievementsByApplicationId(applicationId);
        return ResponseEntity.ok(academicAchievements);
    }

    @GetMapping("/{id}")
    public ResponseEntity<AcademicAchievements> getAcademicAchievementsById(@PathVariable Long id) {
        return academicAchievementsService.getAcademicAchievementsById(id)
                .map(ResponseEntity::ok)
                .orElse(ResponseEntity.notFound().build());
    }

    @PutMapping("/{id}")
    public ResponseEntity<AcademicAchievements> updateAcademicAchievements(@PathVariable Long id, @RequestBody AcademicAchievements academicAchievements) {
        AcademicAchievements updatedAcademicAchievements = academicAchievementsService.updateAcademicAchievements(id, academicAchievements);
        return ResponseEntity.ok(updatedAcademicAchievements);
    }

    @DeleteMapping("/{id}")
    public ResponseEntity<Void> deleteAcademicAchievements(@PathVariable Long id) {
        academicAchievementsService.deleteAcademicAchievements(id);
        return ResponseEntity.noContent().build();
    }
}

